﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class Area_N : FormBase1
    {
        public delegate void DoAction(string areacode);//如果有参数的话，定义参数 

        public DoAction FatherRefresh;

        public Area_N()
        {
            InitializeComponent();
        }

        private void CRM_Area_Load(object sender, EventArgs e)
        {
            treeList1.DataSource = my.bw.Area_Get("AreaCode", my.ACID);

        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (dxValidationProvider1.Validate())
            {
                SVC.client.Area area = new SVC.client.Area();
                area.AreaCode = te_AreaCode.Text.Trim();
                area.AreaName = te_AreaName.Text.Trim();
                if (!string.IsNullOrEmpty(popupContainerEdit1.Text))
                {
                    area.ParentCode = popupContainerEdit1.Text.Split(',')[0];
                }
                string r = my.bw.Area_Add(area, my.ACID);
                if (string.IsNullOrEmpty(r))
                {
                    FatherRefresh(te_AreaCode.Text.Trim());
                    this.Close();
                }
                else
                {
                    Comm.ShowErorr(r);
                }
            }
        }

        private void dropDownButton1_Click(object sender, EventArgs e)
        {
            popupContainerControl1.Show();
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            SVC.client.Area a = treeList1.GetDataRecordByNode(treeList1.FocusedNode) as SVC.client.Area;
            if (a == null) return;
            popupContainerEdit1.EditValue = string.Format("{0},{1}", a.AreaCode, a.AreaName);
            popupContainerEdit1.ClosePopup();
        }

        private void btn_kong_Click(object sender, EventArgs e)
        {
            popupContainerEdit1.EditValue = null;
        }
    }
}